<?php

namespace Home\Controller;
use Think\Controller;
 


class IndexController extends BaseController {
	function _initialize(){
		parent::_initialize();
		
	}	
	
	function index(){
		
		$this->display();
	}

	function editUserInfo(){

		
		$this->display();
	}
	
	function changeHeadImg(){
		$nickname = $_POST['nickname'];
		
		if(!$_FILES){
			$data['nickname'] = $nickname ;
			M('user')->where('id=%d',$this->user_id)->save($data);
			echo "修改成功";
			return;
		}

		if ($_FILES["file"]["error"] > 0)
		{
			echo "错误：: " . $_FILES["file"]["error"] . "<br>";
		}
		else
		{
			$filename = $_FILES["file"]["name"];
			// 如果 upload 目录不存在该文件则将文件上传到 upload 目录下
			$path = 'uploads/headimg/' ;
			$res = move_uploaded_file($_FILES["file"]["tmp_name"],$path.$filename);
			if($res){
				$data['headimg'] ='/'.$path.$filename ;
				$data['nickname'] = $nickname ;
				M('user')->where('id=%d',$this->user_id)->save($data);
				echo "修改成功";
			}else{
				echo "修改失败";
			}
		
		}
		
	}
}